Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[internal-dns] break types-only dependencies to dns-service-client #6807

Conversation

sunshowers
Copy link
Contributor

Currently, a number of crates across Omicron use dns-service-client just for
the types, leading tools like ls-apis to have to make exceptions to handle
them.

To resolve this, follow the pattern we've used in other places, particularly
while breaking dependency loops between API and client crates:

  • Introduce a types crate, in this case internal-dns-types, and move the
    shared types (currently in dns-server-api) to the crate. This crate is a
    good place to put config code generally.
  • Use the types from internal-dns-types everywhere via replace directives.

As a result of this, the only code that was left in internal-dns was the
resolver -- so rename the crate to internal-dns-resolver and move that to
internal-dns/resolver. Also move the internal-dns-cli crate to
internal-dns/cli, since that is the general pattern we follow in Omicron.

As a result of this change, code that just needs the types no longer needs to
depend on dns-service-client, allowing us to remove one of the two
dns-service-client-related rules. (I believe the other rule can be removed
once all our dependencies have been bumped.)

There are no changes to the output of cargo xtask ls-apis apis.

Created using spr 1.3.6-beta.1
Comment on lines -113 to -144
impl Ord for types::DnsRecord {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
use types::DnsRecord;
match (self, other) {
// Same kinds: compare the items in them
(DnsRecord::A(addr1), DnsRecord::A(addr2)) => addr1.cmp(addr2),
(DnsRecord::Aaaa(addr1), DnsRecord::Aaaa(addr2)) => {
addr1.cmp(addr2)
}
(DnsRecord::Srv(srv1), DnsRecord::Srv(srv2)) => srv1
.target
.cmp(&srv2.target)
.then_with(|| srv1.port.cmp(&srv2.port)),

// Different kinds: define an arbitrary order among the kinds.
// We could use std::mem::discriminant() here but it'd be nice if
// this were stable over time.
// We define (arbitrarily): A < Aaaa < Srv
(DnsRecord::A(_), DnsRecord::Aaaa(_) | DnsRecord::Srv(_)) => {
std::cmp::Ordering::Less
}
(DnsRecord::Aaaa(_), DnsRecord::Srv(_)) => std::cmp::Ordering::Less,

// Anything else will result in "Greater". But let's be explicit.
(DnsRecord::Aaaa(_), DnsRecord::A(_))
| (DnsRecord::Srv(_), DnsRecord::A(_))
| (DnsRecord::Srv(_), DnsRecord::Aaaa(_)) => {
std::cmp::Ordering::Greater
}
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Ord impl should be identical to the automatically-derived one, since that orders stuff from top to bottom (so A, AAAA, and then SRV).

Created using spr 1.3.6-beta.1
);

pub type DnsError = crate::Error<crate::types::Error>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved DnsError here because it makes the most sense here.

Comment on lines +403 to +404
Past versions of nexus-types that are still referenced in the dependency tree
depended on dns-service-client for defining some types.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I remove this rule as well, I get this diff:

 DNS Server (client: dns-service-client)
+    consumed by: crucible-downstairs (crucible/downstairs)
+    consumed by: crucible-pantry (crucible/pantry)
+    consumed by: ddmd (maghemite/ddmd)
+    consumed by: dpd (dendrite/dpd)
+    consumed by: mgd (maghemite/mgd)
     consumed by: omicron-nexus (omicron/nexus)
     consumed by: omicron-sled-agent (omicron/sled-agent)
+    consumed by: propolis-server (propolis/bin/propolis-server)

That's what I based this comment on.

Comment on lines +76 to +78
"weight": 0,
"port": 127,
"target": "001de000-c04e-4000-8000-000000000002.host.control-plane.oxide.internal"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reordering here is not important, it happened because we're no longer using progenitor-generated types (which I didn't realize got reordered in alphabetical order!)

Copy link
Contributor

@jgallagher jgallagher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the mechanical changes LGTM, just a couple tiny nits. Will defer to others for the ls-apis question.

internal-dns/types/src/diff.rs Outdated Show resolved Hide resolved
@@ -3062,7 +3062,6 @@
]
},
"DnsConfigParams": {
"description": "DnsConfigParams\n\n<details><summary>JSON schema</summary>\n\n```json { \"type\": \"object\", \"required\": [ \"generation\", \"time_created\", \"zones\" ], \"properties\": { \"generation\": { \"type\": \"integer\", \"format\": \"uint64\", \"minimum\": 0.0 }, \"time_created\": { \"type\": \"string\", \"format\": \"date-time\" }, \"zones\": { \"type\": \"array\", \"items\": { \"$ref\": \"#/components/schemas/DnsConfigZone\" } } } } ``` </details>",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume these descriptions were coming from progenitor - do we care that they aren't being replaced by something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah these descriptions are what happens when you use a progenitor-generated type in a Dropshot server, effectively doubling up on progenitor. I don't think it's a huge problem.

Created using spr 1.3.6-beta.1
@sunshowers sunshowers enabled auto-merge (squash) October 10, 2024 19:48
@sunshowers sunshowers merged commit b0639b0 into main Oct 10, 2024
19 checks passed
@sunshowers sunshowers deleted the sunshowers/spr/internal-dns-break-types-only-dependencies-to-dns-service-client branch October 10, 2024 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants